package com.ruoyi.park22.controller;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.park2.domain.Park2;
import com.ruoyi.park2.service.IPark2Service;
import com.ruoyi.park22.domain.Park22;
import com.ruoyi.park22.service.IPark22Service;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/park22/park22")
@Api("index-view")
public class Park22Controller extends BaseController {
    @Autowired
    private IPark22Service iPark22Service;

    @Autowired
    private IPark2Service iPark2Service;

    @GetMapping("/list")
    public TableDataInfo list(Park22 park22){
        startPage();
        List<Park22> list=iPark22Service.selectPark22List(park22);
        return getDataTable(list);
    }
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo (@PathVariable Long id){
        return success(iPark22Service.selectPark22ById(id));
    }

    @PostMapping
    public AjaxResult add(@Validated @RequestBody Park22 park22){
        return toAjax(iPark22Service.insertPark22(park22));
    }

    @PutMapping
    public AjaxResult update(@Validated @RequestBody Park22 park22){
        return toAjax(iPark22Service.updatePark22(park22));
    }
//    @DeleteMapping("/{id}")
//    public AjaxResult delete(@PathVariable Long id){
//        return toAjax(iPark2Service.deletePark2ById(id));
//    }

    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids){
        return toAjax(iPark22Service.deletePark22ByIds(ids));
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<Park22> util = new ExcelUtil<Park22>(Park22.class);
        util.importTemplateExcel(response, "数据");
    }

    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Park22> util = new ExcelUtil<Park22>(Park22.class);
        List<Park22> Park22List = util.importExcel(file.getInputStream());
        String message = iPark22Service.importPark22(Park22List, updateSupport);
        return success(message);
    }

    @PostMapping("/export")
    public void export(Long[] ids,HttpServletResponse response)
    {
        List<Park22> list = iPark22Service.selectPark22ByIds(ids);
        ExcelUtil<Park22> util = new ExcelUtil<Park22>(Park22.class);
        util.exportExcel(response, list, "数据");
    }

    @GetMapping("/dropdown-data")
    public AjaxResult dropdown(Park2 park2){
        List<Park2> list=iPark2Service.selectPark2List(park2);
        return success(list);
}
}
